/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controlador;

import Facade.MaquinariaFacade;
import VO.MaquinariaVO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import vista.MaquinariaBean;

/**
 *
 * @author Jorge
 */
public class IngresarMaquinariaAction extends org.apache.struts.action.Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    private final static String CANCEL = "cancel";
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        boolean resultado;
        MaquinariaFacade facade = new MaquinariaFacade();
        MaquinariaBean datos = (MaquinariaBean)form;
        MaquinariaVO tipo = new MaquinariaVO();
         
        if (isCancelled(request))
        {
             return mapping.findForward(CANCEL);
        }   
        
         tipo.setNombre(datos.getNombre());
         tipo.setNomenclatura(datos.getNomenclatura());
         tipo.setTipoMaquina(datos.getTipoMaquina());
         tipo.setCapPersonas(datos.getCapPersonas());
         tipo.setCapEstanque(datos.getCapEstanque());
         tipo.setMarca(datos.getMarca());
         tipo.setModelo(datos.getModelo());
         tipo.setPotenciaBomba(datos.getPotenciaBomba());
         tipo.setAnio(datos.getAnio());
         tipo.setPaisOrigen(datos.getPaisOrigen());

         //aun no se valida error de bbdd

         resultado = facade.ingresarMaquinaria(tipo);

         if(resultado)
         {
            datos.setAviso("<span style='color:blue'>Ingreso Exitoso</span>");
            request.setAttribute("datosMaquina", datos);
         }

         return mapping.findForward(SUCCESS);
    }
}
